package com.controller;



import com.entity.Document;
import com.entity.StoreHouse;
import com.entity.Team;
import com.entity.User;
import com.entity.base.Result;
import com.mapper.TeamMapper;
import com.mapper.UserMapper;
import com.service.StoreHouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping(value = "/student")
@Slf4j
@Api(tags = "学生相关接口", description = "提供相关的 Rest API")
public class StudentController {

    @Autowired
    TeamMapper teamMapper;

    @Autowired
    UserMapper userMapper;

    @ApiOperation("加入班级")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "user", value = "用户", required = true, dataType = "user", paramType = "body")
    })
    @PostMapping("/addToTeam")
    public Result addToTeam(@RequestBody User user){
        if (user.getTeamId()==0) return Result.error("加入失败");
        userMapper.updateById(user);
        Team team = teamMapper.selectById(user.getTeamId());
        return Result.success(team);
    }

    @ApiOperation("判断学生是否加入班级")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "user", value = "用户", required = true, dataType = "user", paramType = "body")
    })
    @PostMapping("/judgeRole")
    public Result judgeRole(@RequestBody User user){
        if (user.getTeamId()==0) return Result.error("无所属班级");
        return Result.success(teamMapper.selectById(user.getTeamId()));
    }


}
